﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using VersionComparer.Base;

namespace VersionComparer
{
    public partial class XmlFramentViewerControl : UserControl
    {
        public event EventHandler Scrolled;
        public XmlFramentViewerControl()
        {
            InitializeComponent();
            webBrowser1.Scrolled += webBrowser1_Scrolled;
        }
        public void ScrollTo(int horPos, int verPos)
        {
            webBrowser1.HorizontalScrollPos = horPos;
            webBrowser1.VerticalScrollPos = verPos;
        }
        public int HorizontalScrollPos
        {
            get
            {
                return webBrowser1.HorizontalScrollPos;
            }
        }
        public int VerticalScrollPos
        {
            get
            {
                return webBrowser1.VerticalScrollPos;
            }
        }
        void webBrowser1_Scrolled(object sender, EventArgs e)
        {
            Scrolled.Execute(this, e);
        }

        protected override void OnLoad(EventArgs e)
        {
            //webBrowser1.DocumentText = Text;

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            try
            {
                if (!string.IsNullOrEmpty(FragmentText))
                {
                    doc.LoadXml(FragmentText);
                    string file = Path.GetTempFileName() + ".xml";
                    File.WriteAllText(file, FragmentText);
                    webBrowser1.Navigate(file);
                }
            }
            catch
            {
                tabControl1.SelectedIndex = 1;
            }

            
            textBox1.Text = FragmentText;
            base.OnLoad(e);
        }
        public string FragmentText
        {
            get;
            set;
        }
    }
}
